package cfs.formbean;

import java.util.Date;

import cfs.databean.CFSTransaction;
import cfs.databean.Fund;
import cfs.helper.Helper;
import cfs.helper.TransactionTypes;

public class TransactionForm {
	private int transaction_id;
	private int customer_id;
	private int fund_id;
	private Date execute_date;
	private String shares;
	private String transaction_type;
	private String amount;
	private String status;

	private String symbol;
	private String name;
	private String price;

	public TransactionForm(CFSTransaction tran, Fund fund, long price) {
		this.transaction_id = tran.getTransaction_id();
		this.customer_id = tran.getCustomer_id();
		this.fund_id = tran.getFund_id();
		this.execute_date = tran.getExecute_date();
		
		
		
		this.shares = "" + Helper.longToDouble3String(tran.getShares());
		
		
		
		this.transaction_type = gettype(tran.getTransaction_type());
		this.amount = "$" + Helper.longToDouble2String(tran.getAmount());
		this.setStatus(tran.getStatus());

		this.symbol = fund.getSymbol();
		this.name = fund.getName();
		this.price = "$" + Helper.longToDouble2String(price);
	}

	private static String gettype(int type) {
		switch (type) {
		case 1:
			return "DEPOSIT";
		case 2:
			return "CHECK";
		case 3:
			return "BUY";
		case 4:
			return "SELL";
		default:
			return "UNKNOWN";
		}
	}

	public TransactionForm(CFSTransaction tran) {
		this.transaction_id = tran.getTransaction_id();
		this.customer_id = tran.getCustomer_id();
		this.fund_id = tran.getFund_id();
		this.execute_date = tran.getExecute_date();
		this.shares = "";
		this.transaction_type = gettype(tran.getTransaction_type());
		this.amount = "$" + Helper.longToDouble2String(tran.getAmount());
		this.setStatus(tran.getStatus());

		this.symbol = "-";
		this.name = "-";
		this.price = "";
	}

	public TransactionForm(CFSTransaction tran, Fund fund) {
		this.transaction_id = tran.getTransaction_id();
		this.customer_id = tran.getCustomer_id();
		this.fund_id = tran.getFund_id();
		this.execute_date = tran.getExecute_date();
		if (tran.getTransaction_type() == TransactionTypes.BUY_FUND) {
			this.shares = "N/A";
			this.amount = "$" + Helper.longToDouble2String(tran.getAmount());
		} else {
			this.shares = "" + Helper.longToDouble3String(tran.getShares());
			this.amount = "N/A";
		}
		this.transaction_type = gettype(tran.getTransaction_type());
		
		this.setStatus(tran.getStatus());

		this.symbol = fund.getSymbol();
		this.name = fund.getName();
		this.price = "";
	}

	public int getTransaction_id() {
		return transaction_id;
	}

	public void setTransaction_id(int transaction_id) {
		this.transaction_id = transaction_id;
	}

	public int getCustomer_id() {
		return customer_id;
	}

	public void setCustomer_id(int customer_id) {
		this.customer_id = customer_id;
	}

	public int getFund_id() {
		return fund_id;
	}

	public void setFund_id(int fund_id) {
		this.fund_id = fund_id;
	}

	public Date getExecute_date() {
		return execute_date;
	}

	public void setExecute_date(Date execute_date) {
		this.execute_date = execute_date;
	}

	public String getShares() {
		return shares;
	}

	public void setShares(String shares) {
		this.shares = shares;
	}

	public String getTransaction_type() {
		return transaction_type;
	}

	public void setTransaction_type(String transaction_type) {
		this.transaction_type = transaction_type;
	}

	public String getAmount() {
		return amount;
	}

	public void setAmount(String amount) {
		this.amount = amount;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPrice() {
		return price;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
}
